<template>
	<div>
		<SuperTable
	    	ref="table"
	    	path="ADDONS_PROMOTION_TIME_LIST"
	    	:columns="columns"
	    	:params="params"
	    	:loading="true"
	    >
	    	<Button type="primary" slot="header-left" @click="handleGoEdit()">新增限时抢购</Button>
	    	<Form slot="header-right" :mode="filterForm" inline @submit.native.prevent>
                <FormItem label="名称">
                    <Input v-model="filterForm.keywords" placeholder="请输入活动名称搜索" suffix="ios-search" clearable style="width: 240px"></Input>
                </FormItem>
                <Button type="primary" @click="handleSearch">筛选</Button>
	    	</Form>
	        <div slot-scope="{ row }" slot="action">
	        	<Button type="primary" size="small" @click="handleGoEdit({id: row.id})">编辑</Button>
        		<Poptip
			        confirm
			        transfer
			        placement="left"
			        title="是否确认删除此活动？"
			        @on-ok="handleDelete(row.id)"
			    >
			        <Button type="error" size="small">删除</Button>
			    </Poptip>
	        </div>
	    </SuperTable>
	</div>
</template>

<script>
import Util from '@/libs/util.js';
import Tools from '@/libs/tools.js';
import SuperTable from '@/components/SuperTable.vue';
export default {
	name: 'memberGroup',
	components: {
		SuperTable
	},
	data() {
		return {
			params: {
				title: '',
				page: 1,
				limit: 10
			},
			columns: [
                {
                    title: '活动名称',
                    key: 'title'
                },
                {
                    title: '活动开始时间',
                    key: 'start_time',
                    render: (h, params) => {
                    	if(params.row.start_time <= 0) {
                    		return h('span', '--');
                    	}
                    	return h('span', Tools.formatDate(params.row.start_time * 1000, 'yyyy-MM-dd hh:mm:ss'));
                    }
                },
                {
                    title: '活动结束时间',
                    key: 'end_time',
                    render: (h, params) => {
                    	if(params.row.end_time <= 0) {
                    		return h('span', '--');
                    	}
                    	return h('span', Tools.formatDate(params.row.end_time * 1000, 'yyyy-MM-dd hh:mm:ss'));
                    }
                },
                {
                    title: '操作',
                    slot: 'action',
                    align: "center",
                    width: 128
                },
			],
			filterForm: {
				keywords: ''
			}
		}
	},
	mounted() {
		
	},
	methods: {
		// 搜索
		handleSearch() {
			this.params.title = this.filterForm.keywords;
			this.params.page = 1;
		},
		// 编辑
		handleGoEdit(query) {
			this.$router.push({name: 'app_market_flashSale_edit', query});
		},
		// 删除
		handleDelete(id) {
			Util.ajax.post(this.API['ADDONS_PROMOTION_TIME_DELETE'], {id: id}).then((res) => {
				this.$Message.success('删除成功');
				this.$refs.table.init();
			}).catch(() => {
				
			})
		}
	}
}
</script>